<template>
  <div>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;"
    >
      <el-table-column
        prop="username"
        header-align="center"
        align="center"
        label="操作人"
      >
      </el-table-column>
      <el-table-column
        prop="recipient"
        header-align="center"
        align="center"
        label="领取人/归还人"
      >
      </el-table-column>
      <el-table-column
        prop="type"
        header-align="center"
        align="center"
        label="操作类型"
      >
        <template slot-scope="scope">
          {{
            scope.row.type === 0
              ? "领取"
              : scope.row.type === 1
              ? "绑定"
              : scope.row.type === 2
              ? "解绑"
              : scope.row.type === 3
              ? "归还"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="操作时间"
      >
      </el-table-column>
      <el-table-column
        prop="remark"
        header-align="center"
        align="center"
        label="备注"
      >
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageParams.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageParams.limit"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
  </div>
</template>
<script>
export default {
  components: {},
  props: {
    gpsid: {
      type: String
    }
  },
  data() {
    return {
      dataList: [],
      dataListLoading: false,
      pageParams: {
        page: 1,
        limit: 10
      },
      totalPage: 0,
      idParams: {
        gpsId: ""
      }
    };
  },
  watch: {
    gpsid: {
      handler(newValue, oldValue) {
        this.pageParams.page = 1;
      }
    }
  },
  computed: {},
  created() {},
  mounted() {},

  methods: {
    // 获取历史记录
    getHistoryRecordList(id) {
      this.idParams.gpsId = id ? id : this.pageParams.gpsId;
      let params = { ...this.pageParams, ...this.idParams };
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/sys/gps/history/page"),
        method: "get",
        params: this.$http.adornParams(params)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageParams.limit = val;
      this.pageParams.page = 1;
      this.getHistoryRecordList(this.gpsid);
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageParams.page = val;

      this.getHistoryRecordList(this.gpsid);
    }
  }
};
</script>

<style scoped lang="scss"></style>
